<?php

class Topic extends BaseTopic {
	
	public function prepare($new, $item, $inputs) {
		if ($new) {
			$inputs[] = $this->creator->input_text("Tekst", "body", $this->db_access->db_desqlize($item['body']));
		} else {
			$inputs[] = $this->creator->input_field("Info", "info", $this->db_access->db_desqlize($item['info']), 0, 50);
		}
		return $inputs; 
	}

	protected function derive_info() {
		return substr($_POST['link'], 0, 50) . ((strlen($_POST['link']) > 50) ? "&hellip;" : "");
	}

	protected function get_sql_from_post($item_id) {
		$sql = $this->db_access->db_query_insert(
				array('item_id', 'author', 'editor', 'title', 'creation', 'edit', 'postcount'), 
				array($item_id, $_SESSION['user_id'], $_SESSION['user_id'], $this->db_access->db_sqlize($_POST['title']), 'NOW(14)', 'NOW(14)', (intval($_SESSION['member']['postcount'])+1)), "POST");
		$this->db_access->db_do_query($sql);
		$post_id = $this->db_access->db_insert_id();
		$_SESSION['member']['postcount']++;
		$sql = $this->db_access->db_query_update(
				array('postcount', 'member_since', 'last_visit'), 
				array("postcount + 1", 'member_since', 'last_visit'), "MEMBER", "user_id = {$_SESSION['user_id']}");
		$this->db_access->db_do_query($sql);
		return $this->db_access->db_query_insert(array('post_id', 'body'), array($post_id, $this->db_access->db_sqlize($_POST['body'])), "POST_BODY");
	}

	public function check_content($values, $new) {
		if (!$new) {
			return $this->checker->checkExistsAndTags($values, 'info', 'info');	
		}
		return $this->checker->checkBody($values);
	}
}

?>
